package com.kly.sc.api.application.controller.user.request;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.kly.user.dto.ImagesDto;
import com.kly.user.dto.UserChangeDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

@Data
@ApiModel(value = "userChangeReq", description = "个人信息初始化请求参数")
public class UserChangeReq {
    /**
     * 用户昵称
     */
    @ApiModelProperty("用户昵称")
    @NotNull(message = "nickName cannot be empty")
    private String nickName;
    /**
     * 性向
     */
    @ApiModelProperty("性向: 1-男 2-女 0-未知")
    @NotNull(message = "lookingFor cannot be empty")
    private Integer lookingFor;
    /**
     * 头像地址
     */
    @ApiModelProperty("头像地址")
    @NotNull(message = "avatarUrl cannot be empty")
    private String avatarUrl;

    /**
     * 性别 0未知、1男、2女、3武装直升机
     */
    @ApiModelProperty("性别: 1-男 2-女 0-未知")
    @NotNull(message = "gender cannot be empty")
    private Integer gender;

    /**
     * 生日
     */
    @ApiModelProperty("生日")
    @NotNull(message = "birthday cannot be empty")
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM/dd/yyyy")
    private String birthday;

    /**
     * 用户码
     */
    @ApiModelProperty("about me")
    private String aboutMe;

    @ApiModelProperty("用户上传照片")
    @NotNull(message = "images cannot be empty")
    private List<String> images;

    @ApiModelProperty("用户上传照片")
    private List<ImagesDto> imagesV2;

    @ApiModelProperty("兴趣")
    private List<String> interests;

    @ApiModelProperty("社交目的")
    private String socialConnections;

    @ApiModelProperty("身高")
    private String height;

    private boolean hideHeight;

    private Integer constellation;

    @ApiModelProperty("turnOns")
    private List<Integer> turnOnsList;

    @ApiModelProperty("I want选项, 单选，必填")
    private Integer userWant;

    @ApiModelProperty("You accept选项, 多选，可选")
    private List<Integer> youAccept;

    @ApiModelProperty("body shape选项, 多选，可选")
    private List<Integer> bodyShape;

    public static UserChangeDto getUserInfoDto(@RequestBody @Valid UserChangeReq userChange) {
        UserChangeDto userInfoDto = new UserChangeDto();
        BeanUtils.copyProperties(userChange, userInfoDto);
        userInfoDto.setIWant(userChange.getUserWant());
        if (userChange.getBirthday() != null) {
            try {
                userInfoDto.setBirthday(DateUtil.parse(userChange.getBirthday(), "MM/dd/yyyy"));
            } catch (Exception e) {
                // 设置默认时间
                userInfoDto.setBirthday(DateUtil.parse("01/01/2006", "MM/dd/yyyy"));
            }
        }
        return userInfoDto;
    }

}
